package com.sywb.chuangyebao.view;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.sywb.chuangyebao.MyApplication;
import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.contract.GuideContract;

import org.bining.footstone.utils.StatusBarUtils;
import org.bining.footstone.utils.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 开屏页
 */
public class GuideActivity extends BaseStatisticsActivity<GuideContract.Presenter> implements GuideContract.View {

    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.btn_next)
    TextView btnNext;

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.activity_guide;
    }

    @Override
    public void initView(Bundle bundle) {
        StatusBarUtils.setColorByTransparent(this);
        ((MyApplication) getApplication()).getAppComponent().appManager().exitOtherActivity(this);
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }

    @OnClick({R.id.btn_next, R.id.tv_jump})
    public void onClick(View v) {
        if (!isCanClick(v)) return;
        switch (v.getId()) {
            case R.id.btn_next:
            case R.id.tv_jump:
                mPresenter.clickNext();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        exit();
    }

    @Override
    public void exit() {
        long newClickTime = System.currentTimeMillis();
        if (newClickTime - oldClickTime < 1000) {
            moveTaskToBack(false);
        } else {
            oldClickTime = newClickTime;
            ToastUtils.show(mActivity, R.string.app_exit);
        }
    }

    @Override
    public boolean useSwipeFinish() {
        return false;
    }

    @Override
    public boolean useLightMode() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
    }

    @Override
    public ViewPager getViewPager() {
        return viewpager;
    }

    @Override
    public TextView getButton() {
        return btnNext;
    }

}
